﻿using Company.IO.Interfaces;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Company.System.IO.IntegrationTests
{
    /// <summary>
    ///This is a test class for DirectoryInfoTest and is intended
    ///to contain all DirectoryInfoTest Unit Tests
    ///</summary>
    [TestClass]
    public partial class DirectoryInfoTest : TestBase<IDirectoryInfo>
    {
        private const string _SStringNull = null;
        private const string _SLocalPath = ".\\";
        private static string _classRoot;
        private string _testRoot;


        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        private IDirectoryInfo DirectoryInfo
        {
            get { return ObjectToTest; }
        }

        [ClassInitialize]
        public static void ClassInit(TestContext context)
        {
            _classRoot = global::System.IO.Path.GetFullPath(
                string.Format("{0}Company.System.IO.IntegrationTests\\DirectoryInfoTest\\",
                              global::System.IO.Path.GetTempPath()));

            if (global::System.IO.Directory.Exists(_classRoot))
            {
                global::System.IO.Directory.Delete(_classRoot, true);
            }
            global::System.IO.Directory.CreateDirectory(_classRoot);
        }

        [ClassCleanup]
        public static void ClassCleanup()
        {
        }

        [TestInitialize]
        public void Initialize()
        {
            _testRoot = string.Format("{0}{1}\\", _classRoot, TestContext.TestName);
            if (global::System.IO.Directory.Exists(_testRoot))
            {
                global::System.IO.Directory.Delete(_testRoot, true);
            }

            global::System.IO.Directory.CreateDirectory(_testRoot);

            ObjectToTest = CreateTestDirectoryInfo(_testRoot);
        }

        [TestCleanup]
        public void CleanUp()
        {
            ObjectToTest = null;
        }


        private static IDirectoryInfo CreateTestDirectoryInfo(string currentDir)
        {
            IDirectoryInfo directoryInfo = new DirectoryInfo(new global::System.IO.DirectoryInfo(currentDir));

            global::System.IO.Directory.SetCurrentDirectory(currentDir);

            return directoryInfo;
        }
    }
}